package com.kaishengit.service;

import com.kaishengit.util.StringUtil;

public class SaleServic {
	public String getWhere(String starttime, String endtime, String danwei,
			String tr, String minnum,String maxnum, String from, String mintotal, String maxtotal) {

		StringBuilder sb = new StringBuilder();
		String where = "";
		sb.append("where ");
		if (!StringUtil.isEmpty(danwei)) {
			sb.append("compname = '").append(danwei).append("' and ");
		}
		if (!StringUtil.isEmpty(tr)) {
			sb.append("trname = '").append(tr).append("' and ");
		}
		if (!StringUtil.isEmpty(from)) {
			sb.append("`from` = '").append(from).append("' and ");
		}
		if (!StringUtil.isEmpty(minnum)) {
			sb.append("num>  ").append(minnum).append(" and ");
		}
		if (!StringUtil.isEmpty(maxnum)) {
			sb.append("num<  ").append(maxnum).append(" and ");
		}
		if (!StringUtil.isEmpty(starttime)) {
			sb.append("time >'").append(starttime).append("' and ");
		}
		if (!StringUtil.isEmpty(endtime)) {
			sb.append("time <'").append(endtime).append("' and ");
		}
		if (!StringUtil.isEmpty(mintotal)) {
			sb.append("totalmoney >").append(mintotal).append(" and ");
		}
		if (!StringUtil.isEmpty(maxtotal)) {
			sb.append("totalmoney <").append(maxtotal);
		}

		if (sb.lastIndexOf("where ") != -1) {
			where = "";
		}
		System.out.println(sb.toString());
		where = sb.toString();
		if (where.endsWith("and ")) {
			where = where.substring(0, sb.lastIndexOf("and ")).toString();
		}
		return where;
	}
}
